<template>
	<view class="page page-fill">
		<u-navbar :is-back="true" :title="title" title-color="white" :background="background"></u-navbar>
		<view class="page-block info-list">
			<view class="item-wapper face-line-upbottom" @click="operator">
				<view class="info-words">头像</view>
				
				<view class="right-wapper">
					<image :src="globalUser.avatarUrl" class="face"></image>
					<view class="arrow-block">
						<image src="../../static/left-gray-arrow.png" class="arrow-ico"></image>
					</view>
				</view>		
			</view>		
			<view class="line-top">
				<view class="line"></view>
			</view>
			
			<!-- 昵称 -->
			<view class="item-wapper" @click="modifyNickname">
				<view class="info-words" >昵称</view>
						
				<view class="right-wapper">
					<view class="gray-fields">
						{{globalUser.nickName}}
					</view>
					<view class="arrow-block">
						<image src="../../static/left-gray-arrow.png" class="arrow-ico"></image>
					</view>
				</view>
			</view>
			
			<view class="line-top">
				<view class="line"></view>
			</view>
			
			<!-- 联系方式 -->
			<view class="item-wapper" @click="modifyBirthday">
				<view class="info-words" >微信号</view>
				
				<view class="right-wapper">
					<view class="gray-fields">
						<!-- 手机号/微信号 -->
						{{globalUser.city}}
					</view>
					<view class="arrow-block">
						<image src="../../static/left-gray-arrow.png" class="arrow-ico"></image>
					</view>
				</view>
			</view>
			
			<view class="line-top">
				<view class="line"></view>
			</view>
			
			<!-- 性别 -->
			<view class="item-wapper" @click="modifySex">
				<view class="info-words">性别</view>
				
				<view class="right-wapper">
					<view class="gray-fields">
						
						<view v-if="globalUser.gender == 1">
							男
						</view>
						<view v-else-if="globalUser.gender == 0">
							女
						</view>
						<view v-else>
							未选择
						</view>
						
					</view>
					<view class="arrow-block">
						<image src="../../static/left-gray-arrow.png" class="arrow-ico"></image>
					</view>
				</view>
			</view>						
		</view>
				
		<view class="footer-wapper">
			<view class="footer-words" @click="cleanStorage">
				清理缓存
			</view>
			<view class="footer-words" style="margin-top: 10upx;" @click="logout">
				退出登录
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title:"个人信息",
				background:{
					backgroundImage:'linear-gradient(to top, #ffd655 0%, #fda085 100%)',
				},
				globalUser: {}
			}
		},
		onLoad() {
			var me = this;
			var globalUser = me.getGlobalUser("globalUser").user;
			me.globalUser = globalUser;
		},
		methods: {
			operator() {
				var me = this;
				var globalUser = me.getGlobalUser("globalUser").user;
				uni.showActionSheet({
					itemList: ["查看我的头像", "从相册选择上传"],
					success(res) {
						var index = res.tapIndex;
						if (index == 0) {
							// 预览头像
							var faceArr = [];
							faceArr.push(globalUser.avatarUrl);
							uni.previewImage({
								urls: faceArr,
								current: faceArr[0]
							})
						} else if (index == 1) {
							// 选择上传头像
							uni.chooseImage({
								count: 1,
								sizeType: ["compressed"],
								sourceType: ["album"],
								success(res) {
									// 获得临时路径
									var tempFilePath = res.tempFilePaths[0];
									uni.navigateTo({
										url: "../meFace/meFace?tempFilePath=" + tempFilePath
									})
									// #ifdef H5
									
									// #endif
									// #ifndef H5
									uni.navigateTo({
										url: "../faceCrop/faceCrop?tempFilePath=" + tempFilePath
									})
									// #endif
								}
							})
							
						}
					}
				})
			},			
			modifySex() {
				uni.navigateTo({
					url: "../gender/gender"
				})
			},
			modifyBirthday() {
				uni.navigateTo({
					url: "../meBirthday/meBirthday"
				})
			},
			modifyNickname() {
				uni.navigateTo({
					url: "../meNickname/meNickname"
				})
			},			
			cleanStorage() {
				//uni.clearStorageSync();
				uni.showToast({
					title: "清理缓存成功",
					mask: false,
					duration: 1500
				})
			},
			logout(){
				var userSkey = this.globalUser.skey;
				uni.removeStorageSync("globalUser");
				uni.switchTab({
					url: "../mine/mine"
				})
			}
			
		}
	}
</script>
 
<style>
	@import url("mineinfo.css");
</style>
